#include "../util.h"

#define ERROR -1

#define TEST_SIZE 10000.0
#define TEST_1_PERCENT 50
#define TEST_2_PERCENT 0
#define TEST_3_PERCENT 100
#define TEST_4_PERCENT 25
#define TEST_5_PERCENT 75
#define TEST_6_PERCENT 33

int main(int argc, char *argv[])
{
    int i;
    int num_true = 0;
    int num_false = 0;

    printf("\n>>> TESTING RANDOM NUMBER GENERATOR <<<\n");

    // TEST #0
    printf("\nTest #0: starting init_rand...\n");
    init_rand();

    // TEST #1
    printf("\nTest #1: rand on 50 percent...\n");
    for (i = 0; i < TEST_SIZE; i++)
    {
        if (bool_rand(TEST_1_PERCENT) == 1) { num_true++; }
        else { num_false++; }
    }
    printf("NUM_true: %d (%2.3f)\tNUM_false: %d (%2.3f)\n", num_true, (double)num_true/TEST_SIZE * 100, num_false, (double)num_false/TEST_SIZE * 100);

    // TEST #2
    printf("\nTest #2: rand on 0 percent...\n");
    num_true = 0;
    num_false = 0;
    for (i = 0; i < TEST_SIZE; i++)
    {
        if (bool_rand(TEST_2_PERCENT) == 1) { num_true++; }
        else { num_false++; }
    }
    printf("NUM_true: %d (%2.3f)\tNUM_false: %d (%2.3f)\n", num_true, (double)num_true/TEST_SIZE * 100, num_false, (double)num_false/TEST_SIZE * 100);

    // TEST #3
    printf("\nTest #3: rand on 100 percent...\n");
    num_true = 0;
    num_false = 0;
    for (i = 0; i < TEST_SIZE; i++)
    {
        if (bool_rand(TEST_3_PERCENT) == 1) { num_true++; }
        else { num_false++; }
    }
    printf("NUM_true: %d (%2.3f)\tNUM_false: %d (%2.3f)\n", num_true, (double)num_true/TEST_SIZE * 100, num_false, (double)num_false/TEST_SIZE * 100);

    // TEST #4
    printf("\nTest #4: rand on 25 percent...\n");
    num_true = 0;
    num_false = 0;
    for (i = 0; i < TEST_SIZE; i++)
    {
        if (bool_rand(TEST_4_PERCENT) == 1) { num_true++; }
        else { num_false++; }
    }
    printf("NUM_true: %d (%2.3f)\tNUM_false: %d (%2.3f)\n", num_true, (double)num_true/TEST_SIZE * 100, num_false, (double)num_false/TEST_SIZE * 100);

    // TEST #5
    printf("\nTest #5: rand on 75 percent...\n");
    num_true = 0;
    num_false = 0;
    for (i = 0; i < TEST_SIZE; i++)
    {
        if (bool_rand(TEST_5_PERCENT) == 1) { num_true++; }
        else { num_false++; }
    }
    printf("NUM_true: %d (%2.3f)\tNUM_false: %d (%2.3f)\n", num_true, (double)num_true/TEST_SIZE * 100, num_false, (double)num_false/TEST_SIZE * 100);

    // TEST #6
    printf("\nTest #6: rand on 33 percent...\n");
    num_true = 0;
    num_false = 0;
    for (i = 0; i < TEST_SIZE; i++)
    {
        if (bool_rand(TEST_6_PERCENT) == 1) { num_true++; }
        else { num_false++; }
    }
    printf("NUM_true: %d (%2.3f)\tNUM_false: %d (%2.3f)\n", num_true, (double)num_true/TEST_SIZE * 100, num_false, (double)num_false/TEST_SIZE * 100);

    printf("\n>>> END TEST <<<\n");

    return 0;
}
